{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "This was used as a checklist and test environment for implementing `vis.view()`."
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": "VBox(children=(HBox(children=(Button(description='▶ Play', layout=Layout(visibility='hidden'), style=ButtonSty…",
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "73b4201308b148e2a6cb9acfdb5ae9a2"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import time\n",
    "from phi.flow import *\n",
    "domain = Domain(x=64, y=64)\n",
    "velocity = domain.staggered_grid(Noise(batch=2))\n",
    "viewer = view(velocity, 'smoke', play=True, style='dark_background', select='frames');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in viewer.range(frames=10):\n",
    "    print(i)\n",
    "    time.sleep(.1)\n",
    "    smoke = domain.scalar_grid(Noise(batch=2))\n",
    "    velocity = domain.staggered_grid(Noise(batch=2))\n",
    "    viewer.log_scalars(loss=1/(1+i))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mValueError\u001B[0m                                Traceback (most recent call last)",
      "\u001B[1;32m<ipython-input-2-e5bc64e74d17>\u001B[0m in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[1;32m----> 1\u001B[1;33m \u001B[1;32mraise\u001B[0m \u001B[0mValueError\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m\u001B[0;32m      2\u001B[0m \u001B[0mviewer\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mrec\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m      3\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n",
      "\u001B[1;31mValueError\u001B[0m: "
     ]
    }
   ],
   "source": [
    "raise ValueError()\n",
    "viewer.rec"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "Wish list:\n",
    "\n",
    "- `view(**config)` where config = plt_args, e.g. `view(colorbar=False)`.\n",
    "- Reuse figures to prevent flickering\n",
    "- Interactive plots  `%matplotlib widget`\n",
    "- Convert to Video, save video\n",
    "- Auto-log scalars that are viewed\n",
    "\n",
    "Bugs:\n",
    "- Duplicate names in variables\n",
    "\n",
    "Done:\n",
    "\n",
    "✓ Graph view\n",
    "✓ Skip some updates, depending on time elapsed (e.g. update every 1-2 seconds)\n",
    "✓ Record: `view(..., record=True/tuple, record_dim='frames'/None).rec[value/name]`\n",
    "✓ Time slider for recorded values\n",
    "✓ Batch sliders\n",
    "✓ `view(..., reduce='frames')`\n",
    "✓ Actions\n",
    "✓ Controls"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "data": {
      "text/plain": "HBox(children=(Label(value='slider'), IntSlider(value=0, layout=Layout(margin='0 0 0 0', width='200px'))))",
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "955bf4d44811452592765f7b6e4d802f"
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from ipywidgets import HBox, Layout, Text, Button, IntSlider, Label\n",
    "box = HBox([Label('slider'), IntSlider(max=100, layout=Layout(width='200px', margin='0 0 0 0'))])\n",
    "box"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}